import {  message,Button } from 'antd';
const ChannelLevel = (props) => {
  const [messageApi, contextHolder] = message.useMessage()
  console.log('prop', props)
  const handlLevel = (index, type) => {
    let arr = [...props.todoList]
    if (index === 0 && type === 'up') {
      messageApi.open({
        type: 'warning',
        content: '已经是优先级最顶层了',
      });
        
    } else {
        if (index === props.todoList.length - 1 && type === 'down') {
          messageApi.open({
            type: 'warning',
            content: '当前优先级已经是最后面了',
          });
        } else {
            console.log('start',arr, index)
            if (type === 'down') {
                arr[index] = arr.splice(arr[index + 1], 1, arr[index])[0]
                
            } else {
                arr[index] = arr.splice(arr[index - 1], 1, arr[index])[0]
            }
            console.log('end',arr, index)
            // 交换后更新todolist
            props.setTodo(arr)
        }
    }
    
}
  return (<>
   {contextHolder}
    <div>
    <Button onClick={() => handlLevel(props.index, 'up')} danger>上</Button>
    <Button onClick={() => handlLevel(props.index, 'down')} danger>下</Button>
    </div>
  </>);
}

export default ChannelLevel;